var t = getApp(), e = t.util, a = t.http.day_salaryPost;
var util = getApp().util
Page({
    data: {
        gz_salary: 0,
        beginDate:[],
        endDate:[],
        gz_data:[],
        page:1,
        scrollheight:0, //scrolviell 高度
    },
    onLoad: function(t) {
      if (t.beginDate && t.endDate){
        this.setData({
          beginDate: JSON.parse(t.beginDate),
          endDate: JSON.parse(t.endDate)
        }), this.gz();
      }
    },
    onReady: function() {
        var t = this;
        setTimeout(function() {
            wx.getSystemInfo({
                success: function(e) {
                    t.setData({
                        system: e
                    });
                }
            });
        }, 500);
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
      //加载更多
    _onScrollToLower: function () {
        if(this.data.page > this.data.total_page){
            wx.showToast({
                title: "没有更多数据",
                icon: "none",
            })
        }else{
            this.gz();
        }
        // a.loadMoreComplete(!0);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return util.shareSet(this, "搜索");
    },
    updateStatus: function() {
        this.setData({
            gongzi_status: 1
        });
    },
    beginDate: function() {
        var t = this.data.beginDate;
        "" == t && (t = e.curRiqi()), this.setData({
            dateType: 1
        });
        var a = this.selectComponent("#bottomDialog"), n = [];
        a._getYear(function(e, i) {
            e ? console.log(e) : a._getMonth(t[0], function(e, o) {
                e ? console.log(e) : (n.push(i.indexOf(t[0])), n.push(o.indexOf(t[1])), n.push(parseInt(t[2]) - 1), 
                a.setData({
                    title: "起始日期",
                    years: i,
                    months: o,
                    modelType: "date",
                    dateIndex: n,
                    hideFlag: !1
                }), a.showModal());
            });
        });
    },
    endDate: function() {
        var t = this.data.endDate;
        "" == t && (t = e.curRiqi()), this.setData({
            dateType: 2
        });
        var a = this.selectComponent("#bottomDialog"), n = [];
        a._getYear(function(e, i) {
            e ? console.log(e) : a._getMonth(t[0], function(e, o) {
                e ? console.log(e) : (n.push(i.indexOf(t[0])), n.push(o.indexOf(t[1])), n.push(parseInt(t[2]) - 1), 
                a.setData({
                    title: "结束日期",
                    years: i,
                    months: o,
                    modelType: "date",
                    dateIndex: n,
                    hideFlag: !1
                }), a.showModal());
            });
        });
    },
    riqiSure: function(t) {
       console.log(t);
        if (1 == this.data.dateType) e.riqiTime(t.detail.join("/")) > e.riqiTime(this.data.endDate.join("/")) && this.setData({
            endDate: ""
        }), this.setData({
            beginDate: t.detail
        }); else if ("" != a) {
            var a = this.data.beginDate.join("/"), n = t.detail.join("/");
            if (e.riqiTime(n) < e.riqiTime(a)) return void wx.showToast({
                title: "结束日期必须大于开始日期",
                icon: "none",
                duration: 2e3
            });
            this.setData({
                endDate: t.detail
            });
        } else this.setData({
            endDate: t.detail
        });
    },
    gz: function() {
        var t = this, e = wx.getStorageSync("hall_info").id, n = wx.getStorageSync("userinfo").token, i = this.data.beginDate.join("-"), o = this.data.endDate.join("-");
        let page = this.data.page
        a({
            token: n,
            hall_id: e,
            type: "",
            sdate: i,
            edate: o,
            page:page,
        }, !0).then(function(e) {
            if(0 == e.code){
                if(e.datas.length){
                    t.setData({
                        gz_data: t.data.gz_data.concat(e.datas),
                        gz_salary: e.total_salary,
                        total_page:e.total_page,
                        page:page+1
                    })
                    //计算scroll的高度
                    t.clcaHeight();

                }else{
                   
                }
            }else if(e.code == 1){
                //没有数据
                t.setData({
                    datais:0   
                })

            }else{
                console.log("接口返回数据失败", e);
            }
        });
    },
    search: function() {
        if(this.data.beginDate && this.data.endDate ){
            this.setData({
                page:1,
                gz_data:[],
                gz_salary:'',
            })
            this.gz()
        }else{
            wx.showToast({
                title: "请选择查找日期",
                icon: "none",
                duration: 2e3
            });
        }
    },
    // onReachBottom(){

    //         this._onScrollToLower() 
    //     // console.log(454554);
    // },
    //计算高度
    clcaHeight(){
        var that = this;
        let query = wx.createSelectorQuery();
        query.select('.scroll-content').boundingClientRect(rect => {
            let listXxkHeight = rect.height;
            //计算sousuo类 的 像素 高度
            let sousuo_gao =  178*wx.getSystemInfoSync().screenWidth/750;
            //计算scroll-view的最大高度
            let maxscrollheight = wx.getSystemInfoSync().windowHeight - sousuo_gao
           
            //scrollheight 
            let scrollheight = maxscrollheight
            if(listXxkHeight < maxscrollheight){
                scrollheight = listXxkHeight
            }
            //
            that.setData({
                scrollheight:scrollheight-1,
                maxscrollheight
            })

        }).exec();
    },
});